<script setup lang="ts">
const locale = zhCn;
import { ElConfigProvider } from "element-plus";
import { useUserStore } from "@/store/modules/user";
import { getEnv } from "@/api/auth/index";
import appsDialog from "@/components/AppsDialog/index.vue";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";

const userStore = useUserStore();
const hasToken = userStore.token;
const appLength = userStore.user.userApps.length;
const appid = userStore.user.userAppid;
const isOperate = userStore.user.isOperate;
// console.log("用户小程序appid", appid, userStore);
const appsRef = ref();

const envData = () => {
  getEnv().then((res: Record<string, any>) => {
    document.title = `短剧管理平台-${
      res.environment == "开发环境" ? "测试版" : "正式版"
    }`;
  });
};

onMounted(() => {
  envData();
  // 当用户登陆了 且 没有设置appid  且 app小程序数大于1 显示
  if (hasToken && !appid && appLength > 1 && !isOperate) {
    appsRef.value.showDialog();
  }
});
</script>

<template>
  <el-config-provider :locale="locale">
    <router-view />
  </el-config-provider>

  <appsDialog ref="appsRef" v-if="!appid" />
</template>
